<?php
namespace Modules\Card\Http\Controllers\Client\V1;

use Illuminate\Http\Request;
use Illuminate\Routing\Controller;

use \Modules\Card\Entities\Card;

use Validator;
use ThrowException;
use DB;
use Auth;

// 订单模块
class CardOrderController extends Controller
{
    public function store(Request $req)
    {
        $rule = [
            'type' => ['required']
        ];
        Validator::make($req->all(), $rule)->fails() && ThrowException::BadRequest(); 

        $user = Auth::requireLoginUser();

        $card = Card::getCardByType($req->type) ?: ThrowException('道具卡不存在');

        $card->buyForUser($user);

        return [];
    }
}
